﻿@page "/AGVDataPage"
@inject AGVDataServer aGVDataServer
<Button Danger Type="@ButtonType.Primary" OnClick="@Resh">
    刷新数据
</Button>
<div>


    @if (AGVDatas == null || AGVDatas.Count == 0)
    {
        <Empty /> }
    else
    {
            <Row>
                @for (int i = 0; i < AGVDatas.Count; i++)
                {
                <AGVDisplay aGVData="@AGVDatas[i]"></AGVDisplay>
                }
            </Row>
     }
        

    </div>
@code {
    private ObservableCollection<AGVData> AGVDatas = new ObservableCollection<AGVData>();
    private bool ReshFlag = false;
    protected override async Task OnInitializedAsync()
    {
        var list = await aGVDataServer.GetAGVDatas();
        if (list != null)
        {
            AGVDatas = new ObservableCollection<AGVData>(list);
        }
        await base.OnInitializedAsync();
    }
    private async void Resh()
    {
        if (!ReshFlag)
        {
            ReshFlag = true;
            var list = await aGVDataServer.GetAGVDatas();
            if (list != null)
            {
                AGVDatas = new ObservableCollection<AGVData>(list);
            }
            await this.InvokeAsync(() => { this.StateHasChanged(); });
            ReshFlag = false;
        }
    }
}
